<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Report Builder &mdash; Documentation</title>
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Documentation" href="index.html" />
    <link rel="up" title="4. Client Side API" href="client_side_widgets.html" />
    <link rel="next" title="Dialog Boxes" href="dialog.html" />
    <link rel="prev" title="Form Widget API" href="form_widget.html" /> 
  </head>
  <body>
    <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="dialog.html" title="Dialog Boxes"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="form_widget.html" title="Form Widget API"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Documentation</a> &raquo;</li>
          <li><a href="client_side_widgets.html" accesskey="U">4. Client Side API</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Report Builder</a><ul>
<li><a class="reference external" href="#search-criteria">Search Criteria</a></li>
<li><a class="reference external" href="#customizing-filters">Customizing Filters</a></li>
<li><a class="reference external" href="#scrubbing-modifying-data-from-the-query">Scrubbing / modifying data from the query</a></li>
<li><a class="reference external" href="#adding-style-to-the-result">Adding style to the result</a></li>
<li><a class="reference external" href="#generating-a-query-by-script-from-client-side">Generating a query by script from client side</a></li>
<li><a class="reference external" href="#report-builder-api">Report Builder API</a></li>
<li><a class="reference external" href="#report-builder-container">Report Builder Container</a></li>
<li><a class="reference external" href="#report-builder-class">Report Builder Class</a></li>
<li><a class="reference external" href="#datatable-class">Datatable Class</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="form_widget.html"
                                  title="previous chapter">Form Widget API</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="dialog.html"
                                  title="next chapter">Dialog Boxes</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/report_builder.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="report-builder">
<h1>Report Builder<a class="headerlink" href="#report-builder" title="Permalink to this headline">¶</a></h1>
<p>The Report Builder structure is as follows:</p>
<div class="highlight-python"><pre>+- Report Builder Container
   |
   +- Report Builder (DocType 1)
   |  |
   |  +- DataTable (Output grid)
   |
   +- Report Bulder (DocType 2)
   |
   ..
   ..</pre>
</div>
<div class="section" id="search-criteria">
<h2>Search Criteria<a class="headerlink" href="#search-criteria" title="Permalink to this headline">¶</a></h2>
<p>Reports with selected columns and filters can be saved by clicking on the &#8220;Save&#8221; link on the top bar of
the Report Builder. The report is saved in a record called <cite>Search Criteria</cite>. Client-side and server-side
scripts can be plugged in by using the <cite>Search Criteria</cite>.</p>
</div>
<div class="section" id="customizing-filters">
<h2>Customizing Filters<a class="headerlink" href="#customizing-filters" title="Permalink to this headline">¶</a></h2>
<p>Customizing of filters is done by declaring the <cite>report.customize_filters</cite> method in the client side of the
<cite>Search Critiera</cite>.</p>
<ul class="simple">
<li>Individual filters in the Report Builder can be accessed by the <cite>filter_fields_dict</cite>. The filter_fields_dict
returns a <a title="_f.Field" class="reference external" href="form_widget.html#_f.Field"><tt class="xref docutils literal"><span class="pre">_f.Field</span></tt></a> object.</li>
<li>Filters can be added by using the <cite>add_filter</cite> method</li>
<li>The filters can be customized by setting properties on the <cite>df</cite> dictionary of the field object.</li>
</ul>
<p>Custom properties of filter fields are</p>
<ul class="simple">
<li><cite>filter_hide</cite> - Hide this standard filter</li>
<li><cite>in_first_page</cite> - Show this filter in the first page</li>
<li><cite>report_default</cite> - Set the value as the default for the filter</li>
<li><cite>insert_before</cite> - Insert this filter before the fieldname identified by this property</li>
<li><cite>ignore</cite> - Ignore this field while building the query</li>
<li><cite>custom</cite> - A property that indicates whether the filter is a custom filter (not a standard field)</li>
</ul>
<p>Example:</p>
<div class="highlight-python"><pre>report.customize_filters = function() {
  // hide exiting filters
  this.hide_all_filters();

  // add a new filter
  this.add_filter({fieldname:'show_group_balance', label:'Show Group Balance', fieldtype:'Select', options:NEWLINE+'Yes'+NEWLINE+'No',ignore : 1, parent:'Account'});

  // show a filter
  this.set_filter_properties('Account','Company',{filter_hide: 0});

  // remove limts - show all records
  this.dt.set_no_limit(1);

  // hide tabs
  $dh(this.mytabs.tabs['Select Columns'])

}</pre>
</div>
</div>
<div class="section" id="scrubbing-modifying-data-from-the-query">
<h2>Scrubbing / modifying data from the query<a class="headerlink" href="#scrubbing-modifying-data-from-the-query" title="Permalink to this headline">¶</a></h2>
<p>The query can be scrubbed on the server side in Python before it. The result data is available as a list-in-a-list
<cite>res</cite>. The output can be modified by updating <cite>res</cite> or declaring a new list-in-a-list <cite>out</cite></p>
<p>Standard lists, dictionary that can be updated</p>
<ul class="simple">
<li><cite>col_idx</cite> - Index of columns by label</li>
<li><cite>colwidths</cite> - list of column widths</li>
<li><cite>colnames</cite> - list of column names</li>
<li><cite>coltypes</cite> - list of column types</li>
<li><cite>colwidths</cite> - list of column <cite>options</cite></li>
<li><cite>filter_values</cite> - dictionary containing values of all filters</li>
</ul>
<p>Example - adding a column:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">colnames</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;Total&#39;</span><span class="p">)</span>
<span class="n">coltypes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;Currency&#39;</span><span class="p">)</span>
<span class="n">colwidths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;120px&#39;</span><span class="p">)</span>
<span class="n">coloptions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span>

<span class="c"># set the index</span>
<span class="n">col_idx</span><span class="p">[</span><span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">colnames</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span>
</pre></div>
</div>
<p>Example - adding the column data:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nb">sum</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">res</span><span class="p">:</span>
  <span class="c"># get the total as sum of 2 columns</span>
  <span class="n">t</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="n">col_idx</span><span class="p">[</span><span class="s">&#39;Val 1&#39;</span><span class="p">]]</span> <span class="o">+</span> <span class="n">r</span><span class="p">[</span><span class="n">col_idx</span><span class="p">[</span><span class="s">&#39;Val 2&#39;</span><span class="p">]]</span>
  <span class="nb">sum</span> <span class="o">+=</span> <span class="n">t</span>

  <span class="c"># add it to the record</span>
  <span class="n">r</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
</pre></div>
</div>
<p>Example - getting value from a filter:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">if</span> <span class="n">filter_values</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;Show sum&#39;</span><span class="p">)</span><span class="o">==</span><span class="s">&#39;Yes&#39;</span><span class="p">:</span>

  <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">,</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="nb">sum</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="section" id="adding-style-to-the-result">
<h2>Adding style to the result<a class="headerlink" href="#adding-style-to-the-result" title="Permalink to this headline">¶</a></h2>
<p>Style can be set on a row by declaring the <cite>beforerowprint</cite> method in the Client Script of the <cite>Search Criteria</cite>
Example:</p>
<div class="highlight-python"><pre>// Example 1: set foreground
report.beforerowprint = function(row){
  if(row.data[‘Amount’] &gt; 20000) {
    row.style.color = ‘GREEN’;
  }
}

// Example 2: set background
report.beforerowprint = function(row){
  if(row.data[‘Amount’] &lt; 1000) {
    row.style.backgroundColor = ‘#FDD’;
  }
}</pre>
</div>
</div>
<div class="section" id="generating-a-query-by-script-from-client-side">
<h2>Generating a query by script from client side<a class="headerlink" href="#generating-a-query-by-script-from-client-side" title="Permalink to this headline">¶</a></h2>
<p>A query can be generated from a script from the client side like in Listing by declaring the <cite>get_query</cite> method.
Note: Do not put ORDER BY and LIMIT as they would be appended by the Report Builder. There are 2 useful lists</p>
<blockquote>
<ul class="simple">
<li>report.selected_fields - list of selected fields in <cite>Table_Name</cite>.`field_name` format</li>
<li>report.filter_vals - dictionary of filter keys and values</li>
</ul>
</blockquote>
<p>Example:</p>
<div class="highlight-python"><pre>report.get_query = function() {
      var query = 'SELECT ' + report.selected_fields.join(', ') +  'FROM `tab..` WHERE ...';
      return query;
}</pre>
</div>
</div>
<div class="section" id="report-builder-api">
<h2>Report Builder API<a class="headerlink" href="#report-builder-api" title="Permalink to this headline">¶</a></h2>
<dl class="data">
<dt id="_r">
<tt class="descname">_r</tt><a class="headerlink" href="#_r" title="Permalink to this definition">¶</a></dt>
<dd>Namespace for all objects related to Report Builder</dd></dl>

</div>
<div class="section" id="report-builder-container">
<h2>Report Builder Container<a class="headerlink" href="#report-builder-container" title="Permalink to this headline">¶</a></h2>
<p>The Report Builder Container is the object that contains ReportBuilder objects for each DocType. This object
is managed automatically by the Framework</p>
<dl class="class">
<dt id="_r.ReportBuilderContainer">
<em class="property">class </em><tt class="descclassname">_r.</tt><tt class="descname">ReportBuilderContainer</tt><a class="headerlink" href="#_r.ReportBuilderContainer" title="Permalink to this definition">¶</a></dt>
<dd><dl class="data">
<dt id="_r.ReportBuilderContainer.rb_dict">
<tt class="descname">rb_dict</tt><a class="headerlink" href="#_r.ReportBuilderContainer.rb_dict" title="Permalink to this definition">¶</a></dt>
<dd>Dictionary of all ReportBuilders. Key is the <cite>DocType</cite></dd></dl>

</dd></dl>

</div>
<div class="section" id="report-builder-class">
<h2>Report Builder Class<a class="headerlink" href="#report-builder-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="_r.ReportBuilder">
<em class="property">class </em><tt class="descclassname">_r.</tt><tt class="descname">ReportBuilder</tt><a class="headerlink" href="#_r.ReportBuilder" title="Permalink to this definition">¶</a></dt>
<dd><dl class="data">
<dt id="_r.ReportBuilder.large_report">
<tt class="descname">large_report</tt><a class="headerlink" href="#_r.ReportBuilder.large_report" title="Permalink to this definition">¶</a></dt>
<dd>Flag indicating a report with many records as output. This will force the user to use &#8220;Export&#8221; only</dd></dl>

<dl class="data">
<dt id="_r.ReportBuilder.filter_fields">
<tt class="descname">filter_fields</tt><a class="headerlink" href="#_r.ReportBuilder.filter_fields" title="Permalink to this definition">¶</a></dt>
<dd>List of all filter fields</dd></dl>

<dl class="data">
<dt id="_r.ReportBuilder.filter_fields_dict">
<tt class="descname">filter_fields_dict</tt><a class="headerlink" href="#_r.ReportBuilder.filter_fields_dict" title="Permalink to this definition">¶</a></dt>
<dd>Dictionary of all filter fields. The key of this dictionary is the doctype + <cite>FILTER_SEP</cite> + label</dd></dl>

<dl class="data">
<dt id="_r.ReportBuilder.dt">
<tt class="descname">dt</tt><a class="headerlink" href="#_r.ReportBuilder.dt" title="Permalink to this definition">¶</a></dt>
<dd>Reference to the <a title="_r.Datatable" class="reference internal" href="#_r.Datatable"><tt class="xref docutils literal"><span class="pre">_r.Datatable</span></tt></a> object of the Report Builder</dd></dl>

<dl class="data">
<dt id="_r.ReportBuilder.mytabs">
<tt class="descname">mytabs</tt><a class="headerlink" href="#_r.ReportBuilder.mytabs" title="Permalink to this definition">¶</a></dt>
<dd><p><cite>TabbedPage</cite> object representing the tabs of the Report Builder. This can be used to hide / show
tabs from the Client Script in the report like:</p>
<div class="highlight-python"><pre>$dh(this.mytabs.tabs['Select Columns'])</pre>
</div>
</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.customize_filters">
<tt class="descname">customize_filters</tt><big>(</big><em>report</em><big>)</big><a class="headerlink" href="#_r.ReportBuilder.customize_filters" title="Permalink to this definition">¶</a></dt>
<dd>The method is called when a new report or Search Criteria is loaded. The method (if exists)
is usually used to customize filters as per the user requirments.</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.hide_all_filters">
<tt class="descname">hide_all_filters</tt><big>(</big><big>)</big><a class="headerlink" href="#_r.ReportBuilder.hide_all_filters" title="Permalink to this definition">¶</a></dt>
<dd>Will set the <cite>df</cite>.`filter_hide` property and hide all filters</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.set_column">
<tt class="descname">set_column</tt><big>(</big><em>doctype</em>, <em>label</em>, <em>value</em><big>)</big><a class="headerlink" href="#_r.ReportBuilder.set_column" title="Permalink to this definition">¶</a></dt>
<dd>Select / unselect a column. <cite>value</cite> must be 0 or 1</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.set_filter">
<tt class="descname">set_filter</tt><big>(</big><em>doctype</em>, <em>label</em>, <em>value</em><big>)</big><a class="headerlink" href="#_r.ReportBuilder.set_filter" title="Permalink to this definition">¶</a></dt>
<dd>Set the value of a filter</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.set_filter_properties">
<tt class="descname">set_filter_properties</tt><big>(</big><em>doctype</em>, <em>label</em>, <em>property_dict</em><big>)</big><a class="headerlink" href="#_r.ReportBuilder.set_filter_properties" title="Permalink to this definition">¶</a></dt>
<dd>Set field properties on a filter as specified in property dict</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.add_filter">
<tt class="descname">add_filter</tt><big>(</big><em>f</em><big>)</big><a class="headerlink" href="#_r.ReportBuilder.add_filter" title="Permalink to this definition">¶</a></dt>
<dd>Add a filter in the by specifying the field properties in a dictionary.</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.get_filter">
<tt class="descname">get_filter</tt><big>(</big><em>doctype</em>, <em>label</em><big>)</big><a class="headerlink" href="#_r.ReportBuilder.get_filter" title="Permalink to this definition">¶</a></dt>
<dd>Returns the <cite>Field</cite> object of that filter</dd></dl>

<dl class="function">
<dt id="_r.ReportBuilder.run">
<tt class="descname">run</tt><big>(</big><big>)</big><a class="headerlink" href="#_r.ReportBuilder.run" title="Permalink to this definition">¶</a></dt>
<dd>Execute the report</dd></dl>

</dd></dl>

</div>
<div class="section" id="datatable-class">
<h2>Datatable Class<a class="headerlink" href="#datatable-class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="_r.Datatable">
<em class="property">class </em><tt class="descclassname">_r.</tt><tt class="descname">Datatable</tt><big>(</big><em>html_fieldname</em>, <em>dt</em>, <em>repname</em>, <em>hide_toolbar</em><big>)</big><a class="headerlink" href="#_r.Datatable" title="Permalink to this definition">¶</a></dt>
<dd><p>The datatable class represents a grid object to show the results with paging etc</p>
<dl class="function">
<dt id="_r.Datatable.add_sort_option">
<tt class="descname">add_sort_option</tt><big>(</big><em>label</em>, <em>value</em><big>)</big><a class="headerlink" href="#_r.Datatable.add_sort_option" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new field for sorting selection - value is the tablename.fieldname for the &#8220;ORDER BY&#8221; clause:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">report</span><span class="o">.</span><span class="n">dt</span><span class="o">.</span><span class="n">add_sort_option</span><span class="p">(</span><span class="s">&#39;ID&#39;</span><span class="p">,</span><span class="s">&#39;`tabMyDT`.`name`&#39;</span><span class="p">);</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="_r.Datatable.set_sort_option_disabled">
<tt class="descname">set_sort_option_disabled</tt><big>(</big><em>label</em>, <em>disabled</em><big>)</big><a class="headerlink" href="#_r.Datatable.set_sort_option_disabled" title="Permalink to this definition">¶</a></dt>
<dd>Will enable / disable sort option by label. To disable, pass disabled = 1 or to enable pass disabled = 0</dd></dl>

<dl class="attribute">
<dt id="_r.Datatable.query">
<tt class="descname">query</tt><a class="headerlink" href="#_r.Datatable.query" title="Permalink to this definition">¶</a></dt>
<dd>Query to be executed (the paging using <cite>LIMIT</cite> &amp; sorting is managed by the datatable)</dd></dl>

<dl class="attribute">
<dt id="_r.Datatable.page_len">
<tt class="descname">page_len</tt><a class="headerlink" href="#_r.Datatable.page_len" title="Permalink to this definition">¶</a></dt>
<dd>Length of a page (default 50)</dd></dl>

<dl class="method">
<dt id="_r.Datatable.set_no_limit">
<tt class="descname">set_no_limit</tt><big>(</big><em>value</em><big>)</big><a class="headerlink" href="#_r.Datatable.set_no_limit" title="Permalink to this definition">¶</a></dt>
<dd>Run the query without adding limits if value = 1, (if value=0) run as standard, with limits</dd></dl>

<dl class="method">
<dt id="_r.Datatable.run">
<tt class="descname">run</tt><big>(</big><big>)</big><a class="headerlink" href="#_r.Datatable.run" title="Permalink to this definition">¶</a></dt>
<dd>Execute the query</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="dialog.html" title="Dialog Boxes"
             >next</a> |</li>
        <li class="right" >
          <a href="form_widget.html" title="Form Widget API"
             >previous</a> |</li>
        <li><a href="index.html">Documentation</a> &raquo;</li>
          <li><a href="client_side_widgets.html" >4. Client Side API</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Rushabh Mehta.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>